#! /usr/bin/python
#coding: utf-8
#import pdb

class ProjectionOfLexicoSemanticDictionaryEntry:
    def __init__(self, word,semsit,st1,st2,st3,st4,comment):
        self.word = word
        self.semsit = semsit
        self.st1 = st1
        self.st2 = st2
        self.st3 = st3
        self.st4 = st4
        self.comment = comment

class ProjectionOfLexicoSemanticDictionary:
    """
         ProjectionOfLexicoSemanticDictionary represents projection of LSD on the input text T:

     """

    def __init__(self, rc, ldb):
        self._rc = rc
        self._lsd = ldb.get_lsd()
        self._build()

    def _build(self):
        self._arls = []
        for r in range(self._rc.get_rows_num()):
            words = self._rc.get_row(r).unit
            sems = self._lsd.get_sems_by_word(words[0])
            for s in sems:
                self._arls.append(ProjectionOfLexicoSemanticDictionaryEntry(
                    words[0],
                    s[3],
                    s[4],
                    s[5],
                    s[6],
                    s[7],
                    s[8]))
            if not len(sems):
                self._arls.append(ProjectionOfLexicoSemanticDictionaryEntry(
                    words[0],
                    None,
                    None,
                    None,
                    None,
                    None,
                    u'Не содежится в лсс'))


    def get_first_sem(self, word):
        for j in range(len(self._arls)):
            if self._arls[j].word == word:
                return j

    def get_sort_for_item(self, item, snum):
        result = None
        if snum == 1:
            result = self._arls[item].st1
        if snum == 2:
            result = self._arls[item].st2
        if snum == 3:
            result = self._arls[item].st3
        if snum == 4:
            result = self._arls[item].st4

        return result

    def get_rows_num_by_sem(self, num):
        word = self._arls[num].word
        j = 1
        #print '***' + word
        for i in range(num + 1, len(self._arls)):
            #print self._arls[i].word
            if self._arls[i].word == word:
                j += 1
            else: return j
        return j

    def get_array(self):
        return self._arls
